package ar.arcraft.core;


import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.command.Command;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.bukkit.event.EventHandler;
import org.bukkit.event.Listener;
import org.bukkit.event.player.PlayerJoinEvent;
import org.bukkit.plugin.java.JavaPlugin;

import utils.database.MySQL;
 
public class Main extends JavaPlugin implements Listener {
	MySQL mySQL;
	
	public void onEnable(){
		getLogger().info("Disabled!");
		loadConfiguration();
		mySQL = Arcraft.mysqlConnect(this);
		Bukkit.getPluginManager().registerEvents(this, this);
	}
	
	public void onDisable(){
		getLogger().info("Enabled!");
	}
	
	public boolean onCommand(CommandSender sender, Command cmd, String label, String[] args){
		Player player = (Player) sender;
		if(cmd.getName().equalsIgnoreCase("avip")){
			int errorCode = Vip.setVip(args[0], mySQL, player);
			if(errorCode == 4){
				player.sendMessage(ChatColor.AQUA + "Ese Vip no esta en el sistema con tu nombre, si pagaste contacta a cesar.d.moro en skype");				
			}
			if(errorCode == 3){
				player.sendMessage(ChatColor.AQUA + "Hay un error en la base de datos intenta mas tarde");				
			}
			if(errorCode == 2){
				player.sendMessage(ChatColor.AQUA + "Tu Vip esta activado que lo disfrutes");				
			}
			//Arcraft.executeCommandAsPlayer(player, "kit "+args[0]);
			player.sendMessage(ChatColor.AQUA + "BIRRA FTW4");
		}
		return false;
	}
	@EventHandler 
	public void onLogin(PlayerJoinEvent event) {
	    event.getPlayer().sendMessage(ChatColor.AQUA + "BIRRA FTW");
	}
	
	
	public void loadConfiguration(){
		 
		//See "Creating you're defaults"
	    this.getConfig().options().copyDefaults(true); // NOTE: You do not have to use "plugin." if the class extends the java plugin
	    //Save the config whenever you manipulate it
	    this.saveConfig();
	}
}
